/*******************************************************************
 * author   :  Charlies-ls
 * Date     :  2021-09-26
 * Function :  dict, key is string and value is pointer
 * Copyright (c) 2021. artestplay@outlook.com. All Rights Reserved.
 *******************************************************************/

#ifndef AX_DICT_H_
#define AX_DICT_H_

#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "ax_hashtable.h"
typedef struct ax_hashtable       ax_dict;
typedef struct ax_hashtable_entry ax_dict_entry;
ax_dict* ax_dict_create(AX_HT_FLAGS flags);
void     ax_dict_destory(ax_dict*h);
void     ax_dict_insert(ax_dict*d,const char* key, const void* value);
void*    ax_dict_get(ax_dict*d,const char*key);
bool     ax_dict_remove(ax_dict*d,const char*key);
bool     ax_dict_contains(ax_dict*d,const char* key);
uint32_t ax_dict_size(ax_dict* table);
void     ax_dict_clear(ax_dict* table);

/* should not call by user direct */
void* ax_dict_entry_get_key(void* entry);
void* ax_dict_entry_get_value(void* entry);
void* ax_dict_get_head(ax_dict* table);
#define ax_dict_foreach(key, value, table) \
for(ax_list_node* __node__=ax_dict_get_head(table);\
     __node__!=(key=ax_dict_entry_get_key(__node__), value=ax_dict_entry_get_value(__node__), NULL);\
     __node__=__node__->next)

#endif

